package com.open.party.cloud.view.examine

import android.os.Bundle
import cn.android.x.model.data.AppPageData
import cn.android.x.model.data.ResultInfo
import cn.android.x.parent.AppEventBusTitleBaseActivity
import com.open.party.cloud.R
import com.open.party.cloud.model.ArticleEntity
import com.open.party.cloud.model.ExamineClassMemberCheckVo
import com.open.party.cloud.model.SuggestionVo
import com.open.party.cloud.viewModel.BizViewModel
import com.sinothk.android.utils.XUtils
import kotlinx.android.synthetic.main.activity_examine_class_member_check.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class ExamineClassMemberCheckActivity : AppEventBusTitleBaseActivity() {
    var id: String? = null
    var viewModel: BizViewModel? = null
    var state = "pass"
    override fun getLayoutResId(): Int = R.layout.activity_examine_class_member_check

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setViewTitle("入班审批")
        id = intent.getStringExtra("id")
        viewModel = BizViewModel()

        submitBtn.setOnClickListener {
            submit()
        }

        checkRG.setOnCheckedChangeListener { group, checkedId ->
            when(checkedId){
                R.id.passRb->{
                    XUtils.toast().show("111")
                    state = "pass"
                }
                R.id.backRb->{
                    XUtils.toast().show("2222")
                    state = "back"
                }
            }
        }
    }

    private fun submit() {
        //            val nameStr = userNameEt.text.toString()
//            val phoneNumStr = phoneNumEt.text.toString()

        val vo = ExamineClassMemberCheckVo();

        val contentStr = contentEt.text.toString()
        if (XUtils.string().isEmpty(contentStr)) {
            XUtils.toast().show("请输入意见建议内容")
            return
        }

        if (!XUtils.net().isAvailable) {
            XUtils.toast().show("当前网络不可用")
            return
        }

        vo.id = id
        vo.state = state
        vo.remark = contentStr

        showLoadingDialog("提交中")
        viewModel!!.submitClassMemberCheck(vo)
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public fun eventBusCallback(result: ResultInfo<AppPageData<ArticleEntity>>) {
        if (result.eventType != "submitClassMemberCheck") {
            return
        }

        hideLoadingDialog()

        when (result.code) {
            ResultInfo.SUCCESS -> {
                if (result.data != null) {
                    XUtils.toast().show("提交成功")
                    finish()
                } else {
                    XUtils.toast().show("数据异常")
                }
            }
            ResultInfo.TOKEN_OVERDUE -> {
            }
            else -> {
                XUtils.toast().show(result.msg)
            }
        }
    }
}